package com.example.wifi4client;

import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

public class CloseSocketTask implements Runnable {
    public WeakReference<ConnectTask> mRefConnectTask;
    public CloseSocketTask(ConnectTask connectTask){
        mRefConnectTask = new WeakReference<ConnectTask>(connectTask);
    }
    @Override
    public void run() {
        if (mRefConnectTask.get() !=null &&
            mRefConnectTask.get().mSocket !=null){
            try {
                mRefConnectTask.get().mSocket.close();
                mRefConnectTask.get().mSocket = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
